package com.portal.framework.exception;

import java.io.PrintStream;
import java.io.PrintWriter;

public class AppException extends Exception {

	private static final long serialVersionUID = -3620827757855210270L;
	private Throwable rootcause;
	private Object[] args;
	public Object[] getArgs() {
		return args;
	}
	public void setArgs(Object[] args) {
		this.args = args;
	}
	public Throwable getRootcause() {
		return rootcause;
	}
	public AppException(String message) {
		super(message);
	}

	public AppException(String message,Object... args) {
		super(message);
		this.args = args;
	}

	public AppException(Throwable cause) {
		rootcause = cause;
	}

	public AppException(String message, Throwable cause) {
		super(message);
		rootcause = cause;
	}

	public AppException(String message, Throwable cause,Object... args) {
		super(message);
		rootcause = cause;
		this.args = args;
	}

	public String getMessage() {
		if (rootcause == null)
			return super.getMessage();
		else
			return super.getMessage() + "; cause exception is: \n\t"
					+ rootcause.toString();
	}

	public void printStackTrace() {
		printStackTrace(System.err);
	}

	public void printStackTrace(PrintStream s) {
		if (rootcause == null) {
			super.printStackTrace(s);
		} else {
			s.println(this);
			rootcause.printStackTrace(s);
		}
	}

	public void printStackTrace(PrintWriter s) {
		if (rootcause == null) {
			super.printStackTrace(s);
		} else {
			s.println(this);
			rootcause.printStackTrace(s);
		}
	}

}
